package com.jjyu.controller;

import com.jjyu.entity.RestaurantRating;
import com.jjyu.service.RestaurantRatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ratings")
public class RestaurantRatingController {

    @Autowired
    private RestaurantRatingService restaurantRatingService;

    // 用户对餐厅评分
    @PostMapping("/rate")
    public ResponseEntity<String> rateRestaurant(@RequestParam Long userId, @RequestParam Long restaurantId, @RequestParam Double rating) {
        restaurantRatingService.rateRestaurant(userId, restaurantId, rating);
        return ResponseEntity.ok("Rating added.");
    }

    // 查看用户对餐厅的评分
    @GetMapping("/view")
    public ResponseEntity<RestaurantRating> getUserRating(@RequestParam Long userId, @RequestParam Long restaurantId) {
        RestaurantRating rating = restaurantRatingService.getUserRating(userId, restaurantId);
        return ResponseEntity.ok(rating);
    }

    // 修改评分
    @PostMapping("/update")
    public ResponseEntity<String> updateRating(@RequestParam Long userId, @RequestParam Long restaurantId, @RequestParam Double rating) {
        restaurantRatingService.updateRating(userId, restaurantId, rating);
        return ResponseEntity.ok("Rating updated.");
    }

    // 删除评分
    @PostMapping("/remove")
    public ResponseEntity<String> removeRating(@RequestParam Long userId, @RequestParam Long restaurantId) {
        restaurantRatingService.removeRating(userId, restaurantId);
        return ResponseEntity.ok("Rating removed.");
    }
}
